import os, sys, boto3, django, json
from django.conf import settings



def getTempUrl(filename: str, op: str = "get_object"):
    if op not in ["get_object","put_object"]:
        raise ValueError("only put for get object.")
    s3_client = boto3.client('s3',
                              aws_access_key_id=settings.OSS_AK,
                              aws_secret_access_key=settings.OSS_SK,
                              endpoint_url=settings.OSS_ENDPOINT,
                              region_name=settings.OSS_REGION,
                              )
    response = s3_client.generate_presigned_url(op, {
        "Bucket": settings.OSS_BUCKET,
        "Key": filename,
    })

    return response